#ifndef system_win32_thread_h
#define system_win32_thread_h

#include "..\include\thread.h"

#include <Windows.h>
#include <string>

namespace sys{
	class win32_thread : public thread
	{
		friend DWORD __stdcall thread_proc(LPVOID);
	public:
		virtual dword	release();

		virtual bool	start();

		virtual bool	pause();

		virtual bool	terminal(dword _exit_code);

		virtual bool	join(dword _mesc);

		inline virtual bool	is_paused()		{ if (is_valid()) { return m_is_paused; } return false; }

		inline virtual bool	is_stopped()	{ return !is_valid(); }

		inline virtual kcwstr name()		{ return m_name.c_str(); }

		inline bool		running()			{ return !is_stopped() && !is_paused(); }

		inline bool		is_valid()			{ return m_hthread != 0; }

		win32_thread(kcwstr _name);

		~win32_thread();

		bool create(thread_route* _route, bool _autostart, dword _stack_size);

	protected:
		enum{ TLS_INDEX_THREAD = 0 };

		typedef thread_route route;
		std::wstring	m_name = L"";
		dword	m_stack_size = 0;
		route*	m_proute = nullptr;
		HANDLE	m_hthread = 0;
		bool	m_is_paused = true;
	};
}
#endif	//system_win32_thread_h
